home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
OLE2BOOK.ZIP
/
CHAP13.ZIP
/
PATRON
/
PAGEMOUS.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-27
|
19KB
|
761 lines
/*
* PAGEMOUS.CPP
* Modifications for Chapter 13: None
*
* Implementation of mouse-related member functions of CPage.
* The remainder is in PAGE.CPP. This separate file keeps this
* grungy hit-testing/drawing code out of our way.
*
* Copyright (c)1993 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#include "patron.h"
//Lookups into the array using g_rgHTCode[x+y*3] in PAGEMOUS.CPP
#define YTOP 0
#define YMID 1
#define YBOT 2
#define XLEFT 0
#define XMID 1
#define XRIGHT 2
//Values to restrict sizing in CPage::OnMouseMove
#define SIZINGTOP 0x0001
#define SIZINGBOTTOM 0x0002
#define SIZINGLEFT 0x0004
#define SIZINGRIGHT 0x0008
//This array is for hit-testing lookups
static UINT g_rgHTCode[9]={HTTOPLEFT, HTTOP, HTTOPRIGHT
, HTLEFT, HTCLIENT, HTRIGHT, HTBOTTOMLEFT, HTBOTTOM, HTBOTTOMRIGHT};
//This is for restricting tracking based on the hit-test
static UINT g_rguSizingFlags[9]={SIZINGTOP | SIZINGLEFT, SIZINGTOP
, SIZINGTOP | SIZINGRIGHT, SIZINGLEFT, 0, SIZINGRIGHT
, SIZINGBOTTOM | SIZINGLEFT, SIZINGBOTTOM, SIZINGBOTTOM | SIZINGRIGHT};
/*
* CPage::OnRightDown
*
* Purpose:
* Called when the user clicks with the right button on this page.
* If there is an object here, determined by the last hit-test code,
* the we'll make a popup-menu for it.
*
* Parameters:
* uKeys UINT carrying the key state.
* x, y UINT coordinates of the click in device units.
*
* Return Value:
* BOOL Indicates if the action changed the object.
*/
BOOL CPage::OnRightDown(UINT uKeys, UINT x, UINT y)
{
HMENU hMenu;
HMENU hMenuRes;
HINSTANCE hInst;
HWND hWndFrame, hWndT;
POINT pt;
UINT i, cItems;
//Select the tenant under the mouse, if there is one.
if (!FSelectTenantAtPoint(x, y))
return FALSE;
/*
* Get the top-level window to which menu command will go. This will
* be whatever parent doesn't have a parent itself...
*/
hWndT=GetParent(m_hWnd);
while (NULL!=hWndT)
{
hWndFrame=hWndT;
hWndT=GetParent(hWndT);
}
/*
* Build a popup menu for this object with Cut, Copy, Delete, and
* object verbs.
*/
hInst=GETWINDOWINSTANCE(m_hWnd); //Macro in WIN1632.H
hMenuRes=LoadMenu(hInst, MAKEINTRESOURCE(IDR_RIGHTPOPUPMENU));
if (NULL==hMenuRes)
return FALSE;
//Resource-loaded menus don't work, so we'll copy the items.
hMenu=CreatePopupMenu();
cItems=GetMenuItemCount(hMenuRes);
for (i=0; i < cItems; i++)
{
char szTemp[80];
int id, uFlags;
GetMenuString(hMenuRes, i, szTemp, sizeof(szTemp), MF_BYPOSITION);
id=GetMenuItemID(hMenuRes, i);
uFlags=(0==id) ? MF_SEPARATOR : MF_STRING | MF_ENABLED;
AppendMenu(hMenu, uFlags, id, szTemp);
}
DestroyMenu(hMenuRes);
//Munge the Object menu item
m_pTenantCur->AddVerbMenu(hMenu, MENUPOS_OBJECTONPOPUP);
//Enable or disable the Links item.
i=FQueryLinksInPage() ? MF_ENABLED : MF_DISABLED | MF_GRAYED;
EnableMenuItem(hMenu, IDM_EDITLINKS, i | MF_BYCOMMAND);
SETPOINT(pt, x, y);
ClientToScreen(m_hWnd, &pt);
TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON
, pt.x, pt.y, 0, hWndFrame, NULL);
DestroyMenu(hMenu);
return FALSE;
}
/*
* CPage::FSelectTenantAtPoint
*
* Purpose:
* Selects whatever tenant is at the point (x,y) if there is one,
* deselecting the previously selected tenant.
*
* Parameters:
* x, y UINT coordinates of the mouse.
*
* Return Value:
* BOOL TRUE if there is a tenant here, FALSE otherwise.
*/
BOOL CPage::FSelectTenantAtPoint(UINT x, UINT y)
{
UINT iTenant;
LPTENANT pTenant;
iTenant=TenantFromPoint(x, y, &pTenant);
if (NULL==pTenant)
return FALSE;
//If this one is already current, we might be now sizing.
if (pTenant==m_pTenantCur)
return TRUE;
//Deselect the current tenant
if (NULL!=m_pTenantCur)
m_pTenantCur->Select(FALSE);
//Move this tenant to the top of the list
m_iTenantCur=0;
SendMessage(m_hWndTenantList, LB_DELETESTRING, iTenant, 0L);
SendMessage(m_hWndTenantList, LB_INSERTSTRING, 0, (LONG)pTenant);
//Select and repaint the new tenant to show it up front
m_pTenantCur=pTenant;
m_pTenantCur->Repaint();
m_pTenantCur->Select(TRUE);
return TRUE;
}
/*
* CPage::OnLeftDown
*
* Purpose:
* Called when the user clicks with the left button on this page.
* We find the object under that position that is visibly on top
* (always the first one under this location in the page list since
* we paint in reverse order) and select it.
*
* Parameters:
* uKeys UINT carrying the key state.
* x, y UINT coordinates of the click in device units.
*
* Return Value:
* BOOL Indicates if the action changed the object.
*/
BOOL CPage::OnLeftDown(UINT uKeys, UINT x, UINT y)
{
RECT rc;
if (HTCAPTION==m_uHTCode)
return DragDrop(uKeys, x, y);
/*
* See if we have to start sizing (which always happens on current
* tenant). m_uHTCode is set in OnNCHitTest below.
*/
if (HTNOWHERE!=m_uHTCode && HTCLIENT!=m_uHTCode)
{
//We are sizing, so start tracking
m_pTenantCur->RectGet(&m_rcl, TRUE);
SetCapture(m_hWnd);
m_fTracking=TRUE;
m_hDC=GetDC(m_hWnd);
//Place the rectangle exactly where it is on the screen.
RECTFROMRECTL(rc, m_rcl)
OffsetRect(&rc, -(int)m_pPG->m_xPos, -(int)m_pPG->m_yPos);
RECTLFROMRECT(m_rcl, rc);
m_rclOrg=m_rcl;
DrawFocusRect(m_hDC, &rc);
m_pPG->CalcBoundingRect(&rc, TRUE);
RECTLFROMRECT(m_rclBounds, rc);
return FALSE;
}
//Selection logic moved to a function so OnRightDown can use it.
FSelectTenantAtPoint(x, y);
return FALSE;
}
/*
* CPage::OnLeftUp
*
* Purpose:
* Called when the user clicks up with the left button on this page.
* We stop tracking on this message, if necessary, and resize the object.
*
* Parameters:
* uKeys UINT carrying the key state.
* x, y UINT coordinates of the click in device units.
*
* Return Value:
* BOOL Indicates if this action changed the object.
*/
BOOL CPage::OnLeftUp(UINT uKeys, UINT x, UINT y)
{
RECT rc, rcT;
if (!m_fTracking)
return FALSE;
//Remove the dotted rectangle.
RECTFROMRECTL(rc, m_rcl)
DrawFocusRect(m_hDC, &rc);
ReleaseDC(m_hWnd, m_hDC);
ReleaseCapture();
m_fTracking=FALSE;
//If the original and new rects are the same, nothing happened.
RECTFROMRECTL(rcT, m_rclOrg);
if (EqualRect(&rc, &rcT))
return FALSE;
RECTFROMRECTL(rcT, m_rclOrg);
InvalidateRect(m_hWnd, &rcT, TRUE);
//Invalidate on the screen before accounting for scrolling
InvalidateRect(m_hWnd, &rc, TRUE);
//Factor in the scrolling and tell the tenant where it now stands.
OffsetRect(&rc, (int)m_pPG->m_xPos, (int)m_pPG->m_yPos);
RECTLFROMRECT(m_rcl, rc);
m_pTenantCur->RectSet(&m_rcl, TRUE);
UpdateWindow(m_hWnd);
return TRUE;
}
/*
* CPage::OnLeftDoubleClick
*
* Purpose:
* Called when the user double-clicks with the left button on this page.
* We find the object under that position that is visibly on top
* (always the first one under this location in the page list since
* we paint